<template>
	<view class="container">
		<!-- 报价记录列表 -->
		<view class="quote-list">
			<view class="quote-item" v-for="(item, index) in quoteList" :key="item.id">
				<!-- 商品基本信息 -->
				<view class="product-basic">
					<view class="info-row">
						<text class="info-label">询价单号：</text>
						<text class="info-value">{{ item.inquiry_info.inquiry_number }}</text>
					</view>
					<view class="info-row">
						<text class="info-label">询价型号：</text>
						<text class="info-value">{{ item.inquiry_info.model }}</text>
					</view>
					<view class="info-row">
						<text class="info-label">截止时间：</text>
						<text class="info-value deadline">
							{{ $wanlshop.timeFormat(item.inquiry_info.deadline, 'yyyy-mm-dd hh:MM') }}
						</text>
					</view>
				</view>

				<!-- 我的报价信息 -->
				<view class="my-quote">
					<view class="quote-header">
						<text class="quote-title">我的报价</text>
					</view>
					<view class="quote-content">
						<view class="quote-image">
							<image :src="item.image_url || '/static/images/default-product.png'" mode="aspectFill"
								class="product-img"></image>
						</view>
						<view class="quote-details">
							<view class="quote-row">
								<text class="quote-label">数量：</text>
								<text class="quote-value">{{ item.quote_quantity || '--' }}个</text>
							</view>
							<view class="quote-row">
								<text class="quote-label">价格：</text>
								<text class="quote-value price">{{ item.quote_price || '--' }}元</text>
							</view>
							<view class="quote-row" v-if="item.note">
								<text class="quote-label">备注：</text>
								<text class="quote-value remarks">{{ item.note }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>

			<!-- 空状态 -->
			<view class="empty-state" v-if="quoteList.length === 0">
				<image src="/static/images/empty-quote.png" class="empty-image"></image>
				<text class="empty-text">暂无报价记录</text>
				<text class="empty-desc">您还没有进行任何报价</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				reload: true,
				quoteList: [],
				currentPage: 1, //当前页码
				lastPage: 1, //总页码
				status: 'loading',
				contentText: {
					contentdown: ' ',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
			};
		},
		onLoad() {
			this.resetPage();
		},
		onPullDownRefresh() {
			this.resetPage();
		},
		onReachBottom() {
			if (this.currentPage >= this.lastPage) {
				this.status = 'noMore';
			} else {
				this.reload = false;
				this.currentPage = this.currentPage + 1; //页码+1
				this.status = 'loading';
				this.loadData();
			}
		},
		methods: {
			loadData() {
				uni.$uv.http.get('/inquiry/getUserQuotesList', {
					params: {
						page: this.currentPage,
					}
				}).then(res => {
					if (res.res.code == 1) {
						this.quoteList = res.res.data.list;
						this.currentPage = res.data.current_page;
						this.lastPage = res.data.last_page;
						this.status = 'more';
					}
				}).catch(error => {
					this.$wanlshop.msg('获取报价记录失败', 2000, true)
				});
			},
			resetPage() {
				this.reload = true;
				this.status = 'loading';
				this.currentPage = 1;
				this.loadData();
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 30rpx;
		background-color: #f8f9fa;
		min-height: 100vh;
		box-sizing: border-box;
	}

	.quote-list {
		.quote-item {
			background-color: #fff;
			border-radius: 16rpx;
			padding: 30rpx;
			margin-bottom: 24rpx;
			box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.04);
			border: 1rpx solid #f0f0f0;
		}

		.product-basic {
			margin-bottom: 30rpx;
			padding-bottom: 30rpx;
			border-bottom: 1rpx solid #f5f5f5;

			.info-row {
				display: flex;
				align-items: center;
				margin-bottom: 16rpx;

				&:last-child {
					margin-bottom: 0;
				}

				.info-label {
					font-size: 26rpx;
					color: #666;
					flex-shrink: 0;
				}

				.info-value {
					font-size: 26rpx;
					color: #333;
					flex: 1;

					&.deadline {
						color: #fe6600;
						border-radius: 8rpx;
						font-size: 26rpx;
					}
				}
			}
		}

		.my-quote {
			.quote-header {
				margin-bottom: 20rpx;

				.quote-title {
					font-size: 28rpx;
					color: #333;
					font-weight: 500;
				}
			}

			.quote-content {
				display: flex;
				align-items: flex-start;
			}

			.quote-image {
				width: 140rpx;
				height: 140rpx;
				border-radius: 12rpx;
				overflow: hidden;
				margin-right: 24rpx;
				flex-shrink: 0;
				background-color: #f5f5f5;

				.product-img {
					width: 100%;
					height: 100%;
				}
			}

			.quote-details {
				flex: 1;

				.quote-row {
					display: flex;
					align-items: center;
					margin-bottom: 16rpx;

					&.full-width {
						align-items: flex-start;

						.quote-label {
							align-self: flex-start;
							margin-top: 4rpx;
						}

						.quote-value {
							flex: 1;
						}
					}

					.quote-label {
						font-size: 26rpx;
						color: #666;
						width: 80rpx;
						flex-shrink: 0;
					}

					.quote-value {
						font-size: 26rpx;
						color: #333;

						&.price {
							color: #fe6600;
							font-weight: 600;
							font-size: 28rpx;
						}

						&.remarks {
							color: #999;
							font-size: 24rpx;
							line-height: 1.4;
							flex: 1;
						}
					}
				}
			}
		}

		.empty-state {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			padding: 120rpx 0;

			.empty-image {
				width: 200rpx;
				height: 200rpx;
				margin-bottom: 30rpx;
				opacity: 0.6;
			}

			.empty-text {
				font-size: 30rpx;
				color: #999;
				margin-bottom: 16rpx;
			}

			.empty-desc {
				font-size: 26rpx;
				color: #ccc;
			}
		}
	}
</style>